package edu.umd.essic.maskbuilder;

public class Pos {
    private int i, from, to;
    private static String TAB = "\t";
    private static String SPACE = " ";
    
    public Pos() {
        i = 0;
    }
    
    public int getPos(){
        return i;
    }
    
    private void TraceLine(String text){
        String n = text.substring(i,i+1);
        from = i;
        while (n.equalsIgnoreCase(SPACE)||n.equalsIgnoreCase(TAB)){
            from++;
            n = text.substring(from,from+1);
        } 
        to = from;
        while (!n.equalsIgnoreCase(SPACE)&& !n.equalsIgnoreCase(TAB)){
            to++; 
            if(to+1>text.length()) {i = 0; break;}            
            n = text.substring(to,to+1);
            i = to+1;
        }        
    }
    
    public float ReadFloat(String text){
        TraceLine(text);
        float data = Float.parseFloat(text.substring(from,to)); 
        return data; 
    }
    public void SetZero(){
        i = 0;
    }
    
    public int ReadInt(String text){
        TraceLine(text);
        int  data = Integer.parseInt(text.substring(from,to));     
        return data;
    }
    
    public String ReadString(String text){
        TraceLine(text);
        String data = text.substring(from,to);     
        return data;
    }
    
    /*   public int ReadInt(String text){
        int to = text.indexOf(TAB,i);
        if (to==-1){
            to = text.indexOf(" ",i);
            if (to==-1)
                to = text.length();
        }
        int  data = Integer.parseInt(text.substring(i,to));     
        i = to+1; 
        return data;
    }
  */
}
